<?php
namespace app\common;


use app\common\exception\HttpCode;

/**
 * @desc 系统service基类
 * Class AppService
 * @package app\common
 */
abstract class AppService
{
    /**
     * @desc 成功返回
     * @param array $data
     * @return array
     */
    public static function success($data = [])
    {
        return [
            'code' => 0,
            'msg' => 'ok',
            'data' => $data
        ];
    }

    /**
     * 失败抛出错误
     * @param int $code
     * @param string $msg
     * @throws HttpCode
     */
    public static function error($code = 400, $msg = '系统错误')
    {
        $data = [
            'code' => $code,
            'msg' => $msg,
        ];
        throw new HttpCode($data);
    }
}